package com.zone.sdk.module.appstore.entity;

import com.zone.sdk.common.http.base.BaseEntity;
import com.zone.sdk.module.appstore.base.StoreUtils;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

public class AppDetailEntity extends BaseEntity {
    /**
     * 1-4-1 商品ID(SPU)
     */
    String spuId;
    /**
     * 1-4-2 商品名称
     */
    String spuName;
    /**
     * 1-4-3 商品简介（APP：一句话介绍，SCENE：场景描述）
     */
    String description;
    /**
     * 1-4-4 详细介绍（APP：应用介绍，SCENE：场景描述）
     */
    String detailDesc;
    /**
     * 1-4-5 自我推荐语（APP：开发者一句话，SCENE：无）
     */
    String selfRecommendDescription;
    /**
     * 1-4-6 上架时间
     */
    String shelvesTime;
    /**
     * 1-4-7 生效时间
     */
    Date validityStartTime;
    /**
     * 1-4-8 失效时间
     */
    Date validityEndTime;
    /**
     * 1-4-9 价格
     */
    String productPrice;
    /**
     * 1-4-10 下载量
     */
    String downloadCount;
    /**
     * 1-4-11 销售量
     */
    String salesCount;
    /**
     * 1-4-11 服务类目ID（多层级类目关联）
     */
    String categoryId;
    /**
     * 1-4-12 服务类目名称（多层级类目关联）
     */
    String categoryName;
    /**
     * 1-4-13 商品属性
     */
    List<Object> categoryAttr;
    /**
     * 1-4-13-1 商品属性类型（TBD）
     */
    String attrType;
    /**
     * 1-4-13-2 商品属性key
     */
    String attrKey;
    /**
     * 1-4-13-3 商品属性描述
     */
    String attrDesc;
    /**
     * 1-4-13-4 商品属性值
     */
    String attrValue;
    /**
     * 1-4-14 标签
     */
    List<LabelItem> labelList;
    /**
     * 1-4-15 上架状态（0已上架1已下架）
     */
    String shelvesState;
    /**
     * 1-4-16 推荐状态（0未推荐1已推荐）
     */
    String recommendState;
    /**
     * 1-4-17 唯一编码（商品唯一识别码）
     */
    String spuCode;
    /**
     * 1-4-18 租户ID
     */
    String manufacturer;
    /**
     * 1-4-19 素材清单
     */
    List<ResourceItem> resourceList;
    /**
     * 1-4-20 产品评分/星级
     */
    String productScore;
    /**
     * 1-4-21 文件大小
     */
    String fileSize;
    /**
     * 1-4-22 图标(场景目前传的ID，app传的是地址)
     */
    String icon;
    /**
     * 1-4-23 背景色(场景目前传的ID，app传的是地址)
     */
    String color;
    /**
     * 1-4-24 图标地址（资源url地址，APP端需要显示ICON时，建议采用该字段）
     */
    String iconUrl;
    /**
     * 1-4-25 图标背景色值 （#ffffff，APP端需要显示ICON背景色时，建议采用该字段）
     */
    String iconColorValue;
    /**
     * 1-4-26 购买状态：（1：已购买；0：未购买） Tips：购买状态流转请参照下方状态流转图
     */
    String purchaseStatus;
    /**
     * 1-4-27 安装状态：未安装、下载中、已下载、安装中、已安装、卸载中、已卸载 Tips：安装状态流转请参照下方状态流转图
     */
    String installStatus;
    /**
     * 1-4-28 下载/安装进度 百分比 （下载中需要使用该字段展示百分比进度）
     */
    Integer progress;
    /**
     * 1-4-29 app、scene、more
     */
    String statusDictionaryType;
    /**
     * 1-4-29 心愿清单状态 （1：在心愿清单中，0：不在心愿清单中）
     */
    String starStatus;
    /**
     * 1-4-30 车型列表
     */
    List<AppDetailVehicleTypeInfo> vehicleTypeList;
    /**
     * 1-4-30 版本号
     */
    String version;
    /**
     * 1-4-30 版本更新时间
     */
    String versionUpdateTime;
    /**
     * 1-4-30 支持终端类型（0手机端1车机端2全部）
     */
    String supportType;
    /**
     * 1-4-30 网络（4G/5G）
     */
    String netProtocol;
    /**
     * 1-4-30 QQ群
     */
    String qqGroupNo;
    /**
     * 1-4-31 sku列表
     */
    List<AppDetailSku> skuList;


    public String getSpuId() {
        return spuId;
    }

    public void setSpuId(String spuId) {
        this.spuId = spuId;
    }

    public String getSpuName() {
        return spuName;
    }

    public void setSpuName(String spuName) {
        this.spuName = spuName;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getDetailDesc() {
        return detailDesc;
    }

    public void setDetailDesc(String detailDesc) {
        this.detailDesc = detailDesc;
    }

    public String getSelfRecommendDescription() {
        return selfRecommendDescription;
    }

    public void setSelfRecommendDescription(String selfRecommendDescription) {
        this.selfRecommendDescription = selfRecommendDescription;
    }

    public String getShelvesTime() {
        return shelvesTime;
    }

    public void setShelvesTime(String shelvesTime) {
        this.shelvesTime = shelvesTime;
    }

    public Date getValidityStartTime() {
        return validityStartTime;
    }

    public void setValidityStartTime(Date validityStartTime) {
        this.validityStartTime = validityStartTime;
    }

    public Date getValidityEndTime() {
        return validityEndTime;
    }

    public void setValidityEndTime(Date validityEndTime) {
        this.validityEndTime = validityEndTime;
    }

    public String getProductPrice() {
        return productPrice;
    }

    public void setProductPrice(String productPrice) {
        this.productPrice = productPrice;
    }

    public String getDownloadCount() {
        return downloadCount;
    }

    public int getDownCount() {
        return Integer.parseInt(downloadCount);
    }

    public void setDownloadCount(String downloadCount) {
        this.downloadCount = downloadCount;
    }

    public String getSalesCount() {
        return salesCount;
    }

    public void setSalesCount(String salesCount) {
        this.salesCount = salesCount;
    }

    public String getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(String categoryId) {
        this.categoryId = categoryId;
    }

    public String getCategoryName() {
        return categoryName;
    }

    public void setCategoryName(String categoryName) {
        this.categoryName = categoryName;
    }

    public List<Object> getCategoryAttr() {
        return categoryAttr;
    }

    public void setCategoryAttr(List<Object> categoryAttr) {
        this.categoryAttr = categoryAttr;
    }

    public String getAttrType() {
        return attrType;
    }

    public void setAttrType(String attrType) {
        this.attrType = attrType;
    }

    public String getAttrKey() {
        return attrKey;
    }

    public void setAttrKey(String attrKey) {
        this.attrKey = attrKey;
    }

    public String getAttrDesc() {
        return attrDesc;
    }

    public void setAttrDesc(String attrDesc) {
        this.attrDesc = attrDesc;
    }

    public String getAttrValue() {
        return attrValue;
    }

    public void setAttrValue(String attrValue) {
        this.attrValue = attrValue;
    }

    public List<LabelItem> getLabelList() {
        return labelList;
    }

    public void setLabelList(List<LabelItem> labelList) {
        this.labelList = labelList;
    }

    public String getShelvesState() {
        return shelvesState;
    }

    public void setShelvesState(String shelvesState) {
        this.shelvesState = shelvesState;
    }

    public String getRecommendState() {
        return recommendState;
    }

    public void setRecommendState(String recommendState) {
        this.recommendState = recommendState;
    }

    public String getSpuCode() {
        return spuCode;
    }

    public void setSpuCode(String spuCode) {
        this.spuCode = spuCode;
    }

    public String getManufacturer() {
        return manufacturer;
    }

    public void setManufacturer(String manufacturer) {
        this.manufacturer = manufacturer;
    }

    public List<ResourceItem> getResourceList() {
        return resourceList;
    }

    public void setResourceList(List<ResourceItem> resourceList) {
        this.resourceList = resourceList;
    }

    public String getProductScore() {
        return productScore;
    }

    public void setProductScore(String productScore) {
        this.productScore = productScore;
    }

    public String getFileSize() {
        return fileSize;
    }

    public void setFileSize(String fileSize) {
        this.fileSize = fileSize;
    }

    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public String getIconUrl() {
        return iconUrl;
    }

    public void setIconUrl(String iconUrl) {
        this.iconUrl = iconUrl;
    }

    public String getIconColorValue() {
        return iconColorValue;
    }

    public void setIconColorValue(String iconColorValue) {
        this.iconColorValue = iconColorValue;
    }

    public String getPurchaseStatus() {
        return purchaseStatus;
    }

    public void setPurchaseStatus(String purchaseStatus) {
        this.purchaseStatus = purchaseStatus;
    }

    public String getInstallStatus() {
        return installStatus;
    }

    public void setInstallStatus(String installStatus) {
        this.installStatus = installStatus;
    }

    public Integer getProgress() {
        return progress;
    }

    public void setProgress(Integer progress) {
        this.progress = progress;
    }

    public String getStatusDictionaryType() {
        return statusDictionaryType;
    }

    public void setStatusDictionaryType(String statusDictionaryType) {
        this.statusDictionaryType = statusDictionaryType;
    }

    public String getStarStatus() {
        return starStatus;
    }

    public void setStarStatus(String starStatus) {
        this.starStatus = starStatus;
    }

    public List<AppDetailVehicleTypeInfo> getVehicleTypeList() {
        return vehicleTypeList;
    }

    public void setVehicleTypeList(List<AppDetailVehicleTypeInfo> vehicleTypeList) {
        this.vehicleTypeList = vehicleTypeList;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getVersionUpdateTime() {
        return versionUpdateTime;
    }

    public void setVersionUpdateTime(String versionUpdateTime) {
        this.versionUpdateTime = versionUpdateTime;
    }

    public String getSupportType() {
        return supportType;
    }

    public void setSupportType(String supportType) {
        this.supportType = supportType;
    }

    public String getNetProtocol() {
        return netProtocol;
    }

    public void setNetProtocol(String netProtocol) {
        this.netProtocol = netProtocol;
    }

    public String getQqGroupNo() {
        return qqGroupNo;
    }

    public void setQqGroupNo(String qqGroupNo) {
        this.qqGroupNo = qqGroupNo;
    }

    public List<AppDetailSku> getSkuList() {
        return skuList;
    }

    public void setSkuList(List<AppDetailSku> skuList) {
        this.skuList = skuList;
    }

    public String getDetailType() {
        return statusDictionaryType;
    }

    public boolean isApp() {
        AppDetailSku sku = getSku();
        if (null == sku) {
            return true;
        }
        return "1".equals(sku.getAppType());
    }

    public ResourceItem getPreview() {
        for (ResourceItem r : resourceList) {
            if (null != r) {
                if (StoreUtils.RESOURCE_ID_PREVIEW.equals(r.getResourceId())) {
                    return r;
                }
            }
        }
        return null;
    }

    public List<ResourceItem> getScreenshotList() {
        List<ResourceItem> outList = new LinkedList<>();
        for (ResourceItem r : resourceList) {
            if (null != r) {
                if (StoreUtils.RESOURCE_ID_SCREENSHOT.equals(r.getResourceId())) {
                    outList.add(r);
                }
            }
        }
        return outList;
    }

    public void addResourceItem(ResourceItem item) {
        if (null == resourceList) {
            resourceList = new LinkedList<>();
        }
        resourceList.add(item);
    }

    public boolean needPay() {
        return !("0.00".equals(this.productPrice));
    }

    public String getAppType() {
        AppDetailSku sku = getSku();
        if (null == sku) {
            return "1";
        }
        if (sku.getAppType() == null){
            return "1";
        }
        return sku.getAppType();
    }

    public void setAppType(String type) {
        AppDetailSku sku = getSkuWithCreate();
        sku.setAppType(type);
    }

    public String getOneWord() {
        return getDescription();
    }

    public void setOneWord(String oneWord) {
        setDescription(oneWord);
    }

    public String getCode() {
        return getSpuId();
    }

    public void setCode(String code) {
        setSpuId(code);
    }

    public void setName(String name) {
        setSpuName(name);
    }

    public String getName() {
        return getPackageName();
    }

    public String getPackageName() {
        AppDetailSku sku = getSku();
        if (null == sku) {
            return null;
        }
        return sku.getPackageName();
    }

    public void setPackageName(String packageName) {
        AppDetailSku sku = getSkuWithCreate();
        sku.setPackageName(packageName);
    }

    public String getUrl() {
        AppDetailSku sku = getSku();
        if (null == sku) {
            return null;
        }
        return sku.getDownloadUrl();
    }

    public void setUrl(String url) {
        AppDetailSku sku = getSkuWithCreate();
        sku.setDownloadUrl(url);
    }

    public String getProducer() {
        AppDetailSku sku = getSku();
        if (null == sku) {
            return null;
        }
        return sku.getDeveloperName();
    }

    public String getNewVersion() {
        return getVersion();
    }

    public void setVehicleType(String vehicleType) {
        AppDetailSku sku = getSkuWithCreate();
        sku.setVehicleType(vehicleType);
    }

    public String getVehicleType() {
        AppDetailSku sku = getSku();
        if (null == sku) {
            return null;
        }
        return sku.getVehicleType();
    }

    public AppDetailSku getSku() {
        if (null == skuList) {
            return null;
        }
        if (skuList.isEmpty()) {
            return null;
        }
        return skuList.get(0);
    }

    public AppDetailSku getSkuWithCreate() {
        if (skuList == null) {
            skuList = new LinkedList<>();
        }
        AppDetailSku sku;
        if (skuList.isEmpty()) {
            sku = new AppDetailSku();
            skuList.add(sku);
        } else {
            sku = skuList.get(0);
            if (sku == null) {
                skuList.remove(0);
                sku = new AppDetailSku();
                skuList.add(sku);
            }
        }
        return sku;
    }

    public void setDeveloper(String developer) {
        AppDetailSku sku = getSkuWithCreate();
        sku.setDeveloperName(developer);
    }

    public void copy(AppDetailEntity source) {
        this.spuId = source.spuId;
        this.spuName = source.spuName;
        this.description = source.description;
        this.detailDesc = source.detailDesc;
        this.selfRecommendDescription = source.selfRecommendDescription;
        this.shelvesTime = source.shelvesTime;
        this.validityStartTime = source.validityStartTime;
        this.validityEndTime = source.validityEndTime;
        this.productPrice = source.productPrice;
        this.downloadCount = source.downloadCount;
        this.salesCount = source.salesCount;
        this.categoryId = source.categoryId;
        this.categoryName = source.categoryName;
        this.categoryAttr = source.categoryAttr;
        this.attrType = source.attrType;
        this.attrKey = source.attrKey;
        this.attrDesc = source.attrDesc;
        this.attrValue = source.attrValue;
        this.labelList = source.labelList;
        this.shelvesState = source.shelvesState;
        this.recommendState = source.recommendState;
        this.spuCode = source.spuCode;
        this.manufacturer = source.manufacturer;
        this.resourceList = source.resourceList;
        this.productScore = source.productScore;
        this.fileSize = source.fileSize;
        this.icon = source.icon;
        this.color = source.color;
        this.iconUrl = source.iconUrl;
        this.iconColorValue = source.iconColorValue;
        this.purchaseStatus = source.purchaseStatus;
        this.installStatus = source.installStatus;
        this.progress = source.progress;
        this.statusDictionaryType = source.statusDictionaryType;
        this.starStatus = source.starStatus;
        if (source.vehicleTypeList != null) {
            this.vehicleTypeList = new LinkedList<>();
            for (AppDetailVehicleTypeInfo item : source.vehicleTypeList) {
                AppDetailVehicleTypeInfo n = new AppDetailVehicleTypeInfo();
                n.copy(item);
                this.vehicleTypeList.add(n);
            }
        }
        this.version = source.version;
        this.versionUpdateTime = source.versionUpdateTime;
        this.supportType = source.supportType;
        this.netProtocol = source.netProtocol;
        this.qqGroupNo = source.qqGroupNo;
        this.skuList = new LinkedList<>();
        for (AppDetailSku item : source.skuList) {
            AppDetailSku n = new AppDetailSku();
            n.copy(item);
            this.skuList.add(n);
        }
    }


}
